//
//  MDataCompartmentViewController.m
//  Mask
//
//  Created by 郭子一 on 2020/10/2.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "MDataCompartmentViewController.h"

@interface MDataCompartmentViewController ()

@property (nonatomic, strong) UIView *transformView;
@property (nonatomic, strong) UIButton *leftBtn;
@property (nonatomic, strong) UIButton *rightBtn;
@property (nonatomic, strong) UILabel *breathStateLabel;

@end

@implementation MDataCompartmentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeUI];
}

- (void)makeUI
{
    UIView *headerBgView = [[UIView alloc] init];
    headerBgView.frame = CGRectMake(0, 0, 0, 300);
    [self.view addSubview:headerBgView];
    [headerBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.top.equalTo(self.view);
        make.height.mas_equalTo(300);
    }];
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)RGB_VALUE(0x0191FE).CGColor, (__bridge id)RGB_VALUE(0x00C3FE).CGColor, (__bridge id)RGB_VALUE(0xFFFFFF).CGColor];
    //       gradientLayer.locations = @[@0.3, @5.5, @10.0];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(0, 1);
    gradientLayer.frame = CGRectMake(0, 0, kGScreenWidth, 300);
    [headerBgView.layer addSublayer:gradientLayer];
    
    self.navTitleLab = [[UILabel alloc] init];
    self.navTitleLab.font = JSS_FONT_6;
    self.navTitleLab.textAlignment = NSTextAlignmentCenter;
    self.navTitleLab.textColor = RGB_VALUE(0xFFFFFF);
    self.navTitleLab.text = @"数据";
    [self.view addSubview:self.navTitleLab];
    [self.navTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(200);
        make.centerX.offset(0);
        make.height.mas_equalTo(22);
        make.top.offset(64);
    }];
    
    UIView *view = [[UIView alloc] init];
    [self.view addSubview:view];
    view.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    view.layer.cornerRadius = 20;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.height.mas_equalTo(40);
        make.top.equalTo(self.navTitleLab.mas_bottom).offset(19);
    }];
    
    CGFloat widths = (kGScreenWidth - 30 - 6)/2;
    self.transformView = [[UIView alloc] init];
    [view addSubview:self.transformView];
    [self.transformView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(2);
        make.bottom.offset(-2);
        make.width.mas_equalTo(widths);
        make.left.offset(2);
    }];
    // gradient
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,widths,36);
    gl.startPoint = CGPointMake(0.05, 0.1);
    gl.endPoint = CGPointMake(1, 0.5);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:1/255.0 green:145/255.0 blue:254/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:195/255.0 blue:254/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    self.transformView.layer.cornerRadius = 20;
    self.transformView.layer.masksToBounds = YES;
    [self.transformView.layer addSublayer:gl];
    
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.leftBtn setTitle:@"口罩实时气压图" forState:UIControlStateNormal];
    [self.leftBtn setTitleColor:RGB_VALUE(0x5C6066) forState:UIControlStateNormal];
    [self.leftBtn setTitleColor:RGB_VALUE(0xFFFFFF) forState:UIControlStateSelected];
    [self.leftBtn.titleLabel setFont:JSS_FONT_4];
    self.leftBtn.selected = YES;
    [self.leftBtn addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:self.leftBtn];
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(2);
        make.bottom.offset(-2);
        make.width.mas_equalTo(widths);
    }];
    
    self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.rightBtn setTitle:@"历史呼吸健康曲线" forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:RGB_VALUE(0x5C6066) forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:RGB_VALUE(0xFFFFFF) forState:UIControlStateSelected];
    [self.rightBtn.titleLabel setFont:JSS_FONT_4];
    [self.rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:self.rightBtn];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(2);
        make.bottom.right.offset(-2);
        make.width.mas_equalTo(widths);
    }];
    
    UIView *dataview = [[UIView alloc] init];
    dataview.frame = CGRectMake(15,165,345,330);
    dataview.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    dataview.layer.cornerRadius = 10;
    dataview.layer.shadowColor = [UIColor colorWithRed:93/255.0 green:102/255.0 blue:147/255.0 alpha:0.15].CGColor;
    dataview.layer.shadowOffset = CGSizeMake(0,2);
    dataview.layer.shadowOpacity = 1;
    dataview.layer.shadowRadius = 8;
    [self.view addSubview:dataview];
    [dataview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_bottom).offset(20);
        make.left.offset(15);
        make.right.offset(-15);
        make.height.mas_equalTo(330);
    }];
    
    self.breathStateLabel = [[UILabel alloc] init];
    self.breathStateLabel.text = @"当前呼吸健康水平：非常健康";
    self.breathStateLabel.font = JSS_FONT_2;
    self.breathStateLabel.textColor = RGB_VALUE(0x8C8C8C);
    [self.view addSubview:self.breathStateLabel];
    [self.breathStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dataview.mas_bottom).offset(23);
        make.left.offset(25);
        make.right.offset(-25);
        make.height.mas_equalTo(17);
    }];
}

- (void)leftBtnClick:(UIButton *)sender
{
    sender.selected = !sender.selected;
    self.rightBtn.selected = !sender.selected;
    [self.transformView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.offset(2);
    }];
}

- (void)rightBtnClick:(UIButton *)sender
{
    sender.selected = !sender.selected;
    self.leftBtn.selected = !sender.selected;
    CGFloat widths = (kGScreenWidth - 30 - 6)/2;
    [self.transformView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.offset(widths + 2);
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
